package com.mapreduce.salarytotal;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

//map阶段
public class SalaryTotalMapper extends Mapper<LongWritable, Text, IntWritable,IntWritable> {
    private   IntWritable k2 = new IntWritable();
    private IntWritable v2 = new IntWritable();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //1. v1由Text类型转换为String：toString()方法
        String line = value.toString();
        //2. 按逗号进行分词：split(“,”)方法
        String[] datas = line.split(",");
        //3. 取出需要的字段：部门号：字段[7]、工资：字段[5]
        String deptNo = datas[7];
       // IntWritable k2 = new IntWritable();
        k2.set(Integer.parseInt(deptNo));
       // IntWritable v2 = new IntWritable();
        v2.set(Integer.parseInt(datas[5]));
        //4. 输出k2, v2：context.write()方法
         context.write(k2,v2);
    }
}
